<?php

declare(strict_types=1);

namespace app\seller\model;

use sheep\model\Common;
//use app\seller\model\User as UserModel;
use app\user\model\User;
use think\model\concern\SoftDelete;

class Apply extends Common
{
    use SoftDelete;

    protected $name = 'operations_apply';

    protected $append = [
        'status_text',
        'serve_text',  // 将 serve_text 添加到 append 数组中
        'level_text',  // 将 serve_text 添加到 append 数组中
    ];

    public function statusList()
    {
        return [
            '0' => '审核中',
            '1' => '审核通过',
            '2' => '审核驳回'
        ];
    }



    public function serveList()
    {
        $mode = [
            1 => '团购商家',
            2 => '电商商家',
            3 => '供应链商家',
        ];
        return $mode;
    }

    public function levelList()
    {
        $mode = [
            0 => '基础入驻',
            1 => '体验合作',
            2 => '常规合作',
            3 => 'vip合作',
        ];
        return $mode;
    }


    // 新增 getServeTextAttr 方法
    public function getServeTextAttr($value, $data)
    {
        $mode = $this->serveList();

        // 获取 serve 字段的值
        $serveValue = $data['serve'] ?? '';

        // 如果 serve 值为空，则直接返回空字符串
        if (empty($serveValue)) {
            return '';
        }

        // 将 serve 值拆分成数组
        $keys = explode(',', $serveValue);

        // 逐个获取描述并组合成字符串
        $serveTexts = [];
        foreach ($keys as $key) {
            if (isset($mode[$key])) {
                $serveTexts[] = $mode[$key];
            }
        }

        // 将描述用逗号连接成字符串
        return implode(', ', $serveTexts);
    }

    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'id')->field('id, nickname, avatar, mobile');
    }
}
